HAL FLASH types migration

This section provides information about the HAL FLASH types migration.

Note

  • In HAL1, the FLASH driver manages Flash memory operations.

  • In HAL2, depending on the device family, memory operations are managed either by the FLASH driver or by the NVM driver.

  • In this migration guide, when a type exists in both HAL2 FLASH and HAL2 NVM, the migration is illustrated using the HAL2 FLASH name. The same naming rule applies to HAL2 NVM.

  • Example: in HAL1, FLASH_EccInfoTypeDef type becomes:

    • hal_flash_ecc_type_t and hal_flash_ecc_info_t in HAL2 FLASH driver.

    • hal_nvm_ecc_type_t and hal_nvm_ecc_info_t in HAL2 NVM driver.

  • For NVM-based families, the NVM driver provides programming services similar to those of FLASH with minor differences:

    • There is no erase step for NVM memories.

      • Erase-by-address, page erase, bank erase, and FLASH mass erase remain FLASH-specific.

      • For NVM-based families, the only erase service that may be exposed is OBK erase, when that feature exists.

HAL FLASH erase type definition

HAL1

HAL2

typedef struct
{
  uint32_t TypeErase;

  uint32_t Banks;

  uint32_t Sector;

  uint32_t NbSectors;

  uint32_t VoltageRange;

} FLASH_EraseInitTypeDef;

HAL1 FLASH_EraseInitTypeDef consolidated parameters (erase type, bank/page selection, number of pages) into a single init struct. HAL2 adopts direct granular erase APIs instead of a preparatory struct:

  • Page erase (user area): HAL_FLASH_ErasePage() / HAL_FLASH_ErasePage_IT().

  • EDATA page erase (when present): HAL_FLASH_EDATA_ErasePage() / HAL_FLASH_EDATA_ErasePage_IT().

  • Bank erase: HAL_FLASH_EraseBank() / HAL_FLASH_EraseBank_IT().

  • Mass erase (all banks): HAL_FLASH_MassErase() / HAL_FLASH_MassErase_IT().

  • Address-range erase (granular): HAL_FLASH_EraseByAddr() / HAL_FLASH_EraseByAddr_IT().

Related concepts:


HAL FLASH procedure type definition

HAL1

HAL2

 typedef enum
{
  FLASH_PROC_NONE = 0U,
  FLASH_PROC_SECTERASE_BANK1,
  FLASH_PROC_MASSERASE_BANK1,
  FLASH_PROC_PROGRAM_BANK1,
  FLASH_PROC_SECTERASE_BANK2,
  FLASH_PROC_MASSERASE_BANK2,
  FLASH_PROC_PROGRAM_BANK2,
  FLASH_PROC_ALLBANK_MASSERASE
} FLASH_ProcedureTypeDef;

HAL1 FLASH_ProcedureTypeDef enumerated the internal FLASH operation state machine (e.g. NONE, PROGRAM, PROGRAM_LAST, PAGE_ERASE / SECTERASE, MASSERASE variants and sometimes bank-scoped forms) used by HAL to track an in-progress procedure.

HAL2 removes this umbrella enumeration and introduce a handle that retains the context. Each operation is invoked explicitly via its dedicated API:

  • Programming: HAL_FLASH_Program* or granular page/program APIs.

  • Page / bank / mass / address-range erase: HAL_FLASH_ErasePage(), HAL_FLASH_EraseBank(), HAL_FLASH_MassErase(), HAL_FLASH_EraseByAddr(), plus their _IT counterparts.

  • EDATA page erase (if available): HAL_FLASH_EDATA_ErasePage()/..._IT.

Related concept: Fully rework HAL Flash driver APIs.


HAL FLASH advanced option byte program type definition

HAL1

HAL2

typedef FLASH_AdvOBProgramInitTypeDef;

Removed / sequence changed. HAL1 monolithic advanced option bytes programming structure replaced by discrete HAL2 configuration APIs:

  • BOR level: HAL_FLASH_ITF_OB_SetBORLevel/GetBORLevel().

  • Bank swap: HAL_FLASH_ITF_OB_SetBankSwap/GetBankSwap().

  • Debug authentication: HAL_FLASH_ITF_OB_SetDebugAuthenticationMethod/GetDebugAuthenticationMethod().

  • OEM provisioning: HAL_FLASH_ITF_OB_SetRDPOEMKey() / HAL_FLASH_ITF_IsLockedRDPOEM1Key().

  • Page write protection: HAL_FLASH_ITF_OB_EnablePageWRP/DisablePageWRP/IsEnabledPageWRP().

  • HDP area & access protection: HAL_FLASH_ITF_OB_SetHDPArea/GetHDPArea() + HAL_FLASH_ITF_SetHDPExtAccessProtection/GetHDPExtAccessProtection().

  • Boot config lock, key programming (OBK), SRAM ECC, VDDX HSLV, IWDG mode & freeze, Low-power reset generation, etc.

Each field formerly grouped in FLASH_AdvOBProgramInitTypeDef is now an independent call. No replacement typedef exists.

Related concepts:


HAL FLASH block-based attributes type definition

HAL1

HAL2

typedef FLASH_BBAttributesTypeDef;

HAL1 FLASH_BBAttributesTypeDef aggregated boot / security / privilege attributes. HAL2 exposes fine-grained APIs instead of a packed structure:

  • Boot configuration lock: HAL_FLASH_ITF_OB_LockBootConfig/IsLockedBootConfig()

  • OEM provisioning: HAL_FLASH_ITF_OB_SetRDPOEMKey() / HAL_FLASH_ITF_IsLockedRDPOEM1Key()

  • NV state: HAL_FLASH_ITF_OB_SetNVState/GetNVState()

  • HDP area & access protection via HAL_FLASH_ITF_OB_SetHDPArea/GetHDPArea() and HAL_FLASH_ITF_SetHDPExtAccessProtection/GetHDPExtAccessProtection()

  • Page write protection: EnablePageWRP() / DisablePageWRP() / IsEnabledPageWRP().

Privilege / secure attributes are queried or configured per feature.

Related concept: Fully rework HAL Flash driver APIs.


HAL FLASH CRC configuration type definition

HAL1

HAL2

typedef struct
{
  uint32_t TypeCRC;

  uint32_t BurstSize;

  uint32_t Bank;

  uint32_t Sector;

  uint32_t NbSectors;

  uint32_t CRCStartAddr;

  uint32_t CRCEndAddr;

} FLASH_CRCInitTypeDef;

Removed / sequence changed.Replaced by granular CRC configuration APIs detailed here.

Related concept: Fully rework HAL Flash driver APIs.


HAL FLASH cache type definition

HAL1

HAL2

typedef enum
{
  FLASH_CACHE_DISABLED = 0,
  FLASH_CACHE_ICACHE_ENABLED,
  FLASH_CACHE_DCACHE_ENABLED,
  FLASH_CACHE_ICACHE_DCACHE_ENABLED
} FLASH_CacheTypeDef;
  • in HAL2 this enum is removed, the cache configuration is managed via dedicated APIs:

    • Enable/Disable HAL_FLASH_ITF_EnableICache() / HAL_FLASH_ITF_DisableICache().

    • Get cache status: hal_flash_itf_cache_status_t HAL_FLASH_ITF_IsEnabledICache().

    • Reset cache: HAL_FLASH_ITF_ResetICache().

typedef enum
{
  HAL_FLASH_ITF_CACHE_DISABLED
  HAL_FLASH_ITF_CACHE_ENABLED
} hal_flash_itf_cache_status_t;

Related concepts:


HAL FLASH ECC info type definition

HAL1

HAL2

typedef struct
{
  uint32_t               Area;             /*!< Area from which an ECC was detected.
                                                This parameter can be a value of @ref FLASHEx_ECC_Area  */

  uint32_t               Address;          /*!< ECC error address */

  uint32_t               Data;             /*!< ECC failing data */
} FLASH_EccInfoTypeDef;
typedef enum
{
  HAL_FLASH_ECC_FAIL_NONE,    /*!< FLASH ECC fail none                                      */
  HAL_FLASH_ECC_SINGLE,       /*!< FLASH ECC fail ECC single error correction and detection */
  HAL_FLASH_ECC_DOUBLE,       /*!< FLASH ECC fail ECC double error correction and detection */
  HAL_FLASH_ECC_TRIPLE_ERROR, /*!< FLASH ECC fail ECC triple error detection                */
} hal_flash_ecc_type_t;


typedef struct
{
  hal_flash_ecc_type_t      ecc_fail_type; /*!< FLASH ECC fail type    */
  uint32_t                  ecc_fail_addr; /*!< FLASH ECC fail address */
  uint32_t                  data;          /*!< FLASH ECC data         */
  hal_flash_ecc_status_t    status;        /*!< FLASH ECC status       */
} hal_flash_ecc_info_t;

Related concept: Fully rework HAL Flash driver APIs.


HAL FLASH HDP extension type definition

HAL1

HAL2

typedef FLASH_HDPExtensionTypeDef;

HAL1 FLASH_HDPExtensionTypeDef packed extension configuration for Hide Protection (HDP) area (start page, length, access protection mode, level transitions). HAL2 provides granular APIs instead of a struct:

  • Set/Get HDP extension area: HAL_FLASH_ITF_SetHDPExtArea() / HAL_FLASH_ITF_GetHDPExtArea().

  • Set/Get HDP access protection state: HAL_FLASH_ITF_SetHDPExtAccessProtection() / HAL_FLASH_ITF_GetHDPExtAccessProtection(enum hal_flash_itf_hdp_access_protection_t).

  • Set/Get HDP level (series providing HDP levels): HAL_FLASH_ITF_SetHDPLevel() / HAL_FLASH_ITF_GetHDPLevel(enum hal_flash_itf_hdp_level_t).

  • Option bytes HDP area control (enable/disable/query): HAL_FLASH_ITF_OB_SetHDPArea() / HAL_FLASH_ITF_OB_GetHDPArea() / HAL_FLASH_ITF_OB_EnableHDPArea/DisableHDPArea/IsEnabledHDPArea(enum hal_flash_itf_ob_hdp_area_status_t).

Each previous struct field is now represented by an explicit call or small status enumeration. no replacement typedef exists in HAL2.

Related concepts:


HAL FLASH option bytes program type definition

HAL1

HAL2

typedef FLASH_OBProgramInitTypeDef;

HAL1 FLASH_OBProgramInitTypeDef aggregated multiple option bytes fields (BORLevel, UserConfig bits, WRPArea, RDPLevel, NV state, Secure/Privilege flags, HDP area parameters, SRAM ECC, Bank swap, debug authentication, pull-up config, OEM key provisioning, etc) in a single programming structure.

HAL2 decomposes each concern into fine-grained setter/getter or enable/disable/status APIs. Use the dedicated calls:

  • BOR level: HAL_FLASH_ITF_OB_SetBORLevel() / HAL_FLASH_ITF_OB_GetBORLevel(enum hal_flash_itf_ob_bor_level_t).

  • Bank swap (and lock): HAL_FLASH_ITF_OB_SetBankSwap() / HAL_FLASH_ITF_OB_GetBankSwap() / HAL_FLASH_ITF_OB_LockBankSwap/UnlockBankSwap/IsLockedBankSwap().

  • Debug authentication: HAL_FLASH_ITF_OB_SetDebugAuthenticationMethod() / HAL_FLASH_ITF_OB_GetDebugAuthenticationMethod(enum hal_flash_itf_ob_dbg_auth_t).

  • NV state: HAL_FLASH_ITF_OB_SetNVState() / HAL_FLASH_ITF_OB_GetNVState(enum hal_flash_itf_ob_nv_state_t).

  • RDP OEM keys & lock status: HAL_FLASH_ITF_OB_SetRDPOEM1KeySetRDPOEM2Key() / HAL_FLASH_ITF_IsLockedRDPOEM1Key/IsLockedRDPOEM2Key(); CRC via HAL_FLASH_ITF_GetRDPOEM1KeyCRC/GetRDPOEM2KeyCRC().

  • Page write protection: HAL_FLASH_ITF_OB_EnablePageWRP/DisablePageWRP/IsEnabledPageWRP()

  • HDP area (option bytes): HAL_FLASH_ITF_OB_SetHDPArea() / HAL_FLASH_ITF_OB_GetHDPArea() / HAL_FLASH_ITF_OB_EnableHDPArea/DisableHDPArea/IsEnabledHDPArea().

  • HDP extension (if provided by series): HAL_FLASH_ITF_SetHDPExtArea/GetHDPExtArea() / HAL_FLASH_ITF_SetHDPExtAccessProtection/GetHDPExtAccessProtection() / HAL_FLASH_ITF_SetHDPLevel/GetHDPLevel().

  • SRAM ECC option bytes: HAL_FLASH_ITF_OB_EnableSRAMECC/DisableSRAMECC/IsEnabledSRAMECC(enum hal_flash_itf_ob_sram_ecc_status_t).

  • IO pull configuration (e.g. PA15): HAL_FLASH_ITF_OB_SetIOPull().

  • User I/O high-speed low-voltage configuration (HSLV) bits are managed via dedicated user option bytes constants.

Related concept: Fully rework HAL Flash driver APIs.


HAL FLASH operation type definition

HAL1

HAL2

typedef FLASH_OperationTypeDef;
typedef enum
{
  HAL_FLASH_INTERRUPTED_NO_OPERATION,
  HAL_FLASH_INTERRUPTED_SINGLE_WRITE,
  HAL_FLASH_INTERRUPTED_PAGE_ERASE,
  HAL_FLASH_INTERRUPTED_BANK_ERASE,
  HAL_FLASH_INTERRUPTED_MASS_ERASE,
  HAL_FLASH_INTERRUPTED_OB_CHANGE
} hal_flash_interrupted_operation_t;


typedef struct
{
  uint32_t                          addr;      /*!< FLASH interrupted operation address */
  hal_flash_interrupted_operation_t operation; /*!< FLASH interrupted operation code    */
} hal_flash_interrupted_by_reset_operation_info_t;

Related concept: Fully rework HAL Flash driver APIs.


HAL FLASH handle type definition

HAL1

HAL2

typedef FLASH_ProcessTypeDef;

HAL1 FLASH_ProcessTypeDef was an internal/global context structure (procedure enum, bank/page indices, address, remaining pages, error code, lock state).

HAL2 hides this state entirely. each API call carries full intent (page number, bank, address range, key type, etc.) and returns a status (hal_status_t).

Longer operations in IT mode signal completion or errors through callbacks (e.g. HAL_FLASH_OB_ProgramCpltCallback(), HAL_FLASH_OB_ErrorCallback(), HAL_FLASH_ITF_ECC_ErrorCallback()).

Error and progress inspection no longer require exposing a mutable global process struct.

Related concept: Fully rework HAL Flash driver APIs.